<template>
  <div>
    <el-select @change="processChange" clearable v-model="state.value">
      <el-option
        v-for="item in state.dictHandleOptions"
        :key="item.dictCode"
        :label="item.dictLabel"
        :value="item.dictLabel"
      />
    </el-select>
  </div>
</template>
<script lang="ts" setup>
import {
  reactive,
  ref,
  inject,
  onMounted,
  onBeforeUnmount,
  computed,
  watch,
} from "vue";
import { useDictionary } from "@/store/backend/tool/dictionary";
import { TableColumn, TableRow } from "@/utils/baTable";
import { useRegion } from "@/store/backend/SysM/region";
import type baTableClass from "@/utils/baTable";
import useCurrentInstance from "@/utils/useCurrentInstance";

const state: {
  dictHandleOptions: anyObj[];
  value: string | number;
} = reactive({
  dictHandleOptions: [], //废气处理工艺列表 字典项
  value: "",
});

const { proxy } = useCurrentInstance();
const baTable = inject("baTable") as baTableClass;
const dictionary = useDictionary();
const region = useRegion();

interface Props {
  renderValue: any; // 单元格值
  renderRow: TableRow; // 当前行数据
  renderField: TableColumn; // 当前列数据
}
const props = defineProps<Props>();

proxy.eventBus.on("clearTag", () => {
  baTable.comSearch.form[props.renderField as any] = "";
  state.value = "";
});

const processChange = (value: any) => {
  state.value = value;
  if (value === "") {
    baTable.comSearch.form[props.renderField as any] = "";
  } else {
    baTable.comSearch.form[props.renderField as any] = value;
  }
};
const getDictInfo = (name: string) => {
  //获取列表(字典)
  dictionary.getDictInfo(name).then((res: any) => {
    state.dictHandleOptions = res;
    console.log("获取列表(字典)", state.dictHandleOptions);
  });
};
//过滤字典name
const dSwitch = (name: string) => {
  switch (name) {
    case "问题域":
      getDictInfo("sys_problem_area");
      break;
    case "问题状态":
      getDictInfo("sys_problem_status");
      break;
  }
};
onMounted(() => {
  console.log("props", props.renderRow, props.renderField);
  dSwitch(props.renderRow.label);
});
onBeforeUnmount(() => {
  proxy.eventBus.off("clearTag");
});
</script>
<style lang="scss" scoped></style>
